package org.zpmis.domain.project.vo;

import lombok.Data;
import org.zpmis.domain.project.model.ProjectTask;

import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

@Data
public class GetTaskDetailVo {
    /**
     * 任务id
     */
    private Long id;

    /**
     * 任务名称
     */
    private String name;

    /**
     * 任务类型
     */
    private Integer type;

    /**
     * 关联项目id
     */
    private Long projectId;

    /**
     * 任务级别
     */
    private Integer level;

    /**
     * 上级任务
     */
    private Long parentId;

    /**
     * 任务描述
     */
    private String description;

    /**
     * 任务描述附件
     */
    private String descAttachment;

    /**
     * 任务计划开始时间
     */
    private String planStartTime;

    /**
     * 任务计划结束时间
     */
    private String planEndTime;

    /**
     * 任务开始时间
     */
    private String startTime;

    /**
     * 任务结束时间
     */
    private String endTime;

    /**
     * 工时
     */
    private BigDecimal workHours;

    /**
     * 指派给人
     */
    private Long sysUid;

    /**
     * 指派给人
     */
    private String sysUserName;

    /**
     * 任务完成结果
     */
    private String completeResult;

    /**
     * 任务结果附件
     */
    private String resultAttachment;

    /**
     * 任务创建人
     */
    private String createPerson;

    /**
     * 状态 0新建 1进行中 2已完成
     */
    private Integer status;

    /**
     * 创建人id
     */
    private Long createId;

    /**
     * 创建时间
     */
    private String createTime;

    /**
     * 任务进度
     */
    private String progress;

    /**
     * 关联项目名称
     */
    private String projectName;

    public static GetTaskDetailVo toTaskDetailVo(ProjectTask projectTask) {
        if(projectTask == null){
            return null;
        }
        GetTaskDetailVo taskDetailVo = new GetTaskDetailVo();
        taskDetailVo.setId(projectTask.getId());
        taskDetailVo.setName(projectTask.getName());
        taskDetailVo.setType(projectTask.getType());
        taskDetailVo.setProjectId(projectTask.getProjectId());
        taskDetailVo.setLevel(projectTask.getLevel());
        taskDetailVo.setParentId(projectTask.getParentId());
        taskDetailVo.setDescription(projectTask.getDescription());
        taskDetailVo.setDescAttachment(projectTask.getDescAttachment());
        taskDetailVo.setPlanStartTime(projectTask.getPlanStartTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(projectTask.getPlanStartTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        taskDetailVo.setPlanEndTime(projectTask.getPlanEndTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(projectTask.getPlanEndTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        taskDetailVo.setStartTime(projectTask.getStartTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(projectTask.getStartTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        taskDetailVo.setEndTime(projectTask.getEndTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(projectTask.getEndTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        taskDetailVo.setWorkHours(projectTask.getWorkHours());
        taskDetailVo.setSysUid(projectTask.getSysUid());
        taskDetailVo.setCompleteResult(projectTask.getCompleteResult());
        taskDetailVo.setResultAttachment(projectTask.getResultAttachment());
        taskDetailVo.setCreatePerson(projectTask.getCreatePerson());
        taskDetailVo.setStatus(projectTask.getStatus());
        taskDetailVo.setCreateId(projectTask.getCreateId());
        taskDetailVo.setCreateTime(projectTask.getCreateTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(projectTask.getCreateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        taskDetailVo.setProgress(projectTask.getProgress());
        return taskDetailVo;
    }
}
